<?php
namespace app\api\model;
use think\Model;

class Cargo extends Model
{
    protected $autoWriteTimestamp = true;
	protected $updateTime = false;
	protected $pk = 'id';

    // 商品单位
    public function fproduct() {
        return $this->hasOne('\app\api\model\Product','id','product_id')->bind(
            ['name', 'code', 'specification', 'unit_id', 'type_id', 'unit', 'type', 'purchase', 'price']
        );
	}
	
	// 获取仓库商品
	public static function getCargoProducts($id) {
		$result = self::with([
			'fproduct' => function ($query) {
				$query->with(['funit', 'ftype'])
					->order(['id' => 'desc']);
			}
		])
		->where('warehouse_id', $id)
		->select();

		return $result;
	}
}

